import { _decorator, Animation, BoxCollider2D, Button, color, Component, director, ERigidBody2DType, Event, EventTouch, find, instantiate, Intersection2D, Label, log, Material, Node, PolygonCollider2D, Prefab, RigidBody2D, Sprite, Tween, tween, UIOpacity, UITransform, v2, v3, Vec2, Vec3 } from 'cc';
import { tongyongTS } from '../tongyongTS/tongyongTS';
import { weixinapi } from '../tongyongTS/weixinAIP';
import { SJTS } from '../../../jinruchangjing/SJTS';
const { ccclass, property } = _decorator;

@ccclass('xiaogeqiuTS')
export class xiaogeqiuTS extends Component {
    @property(Node) z子牌: Node = null;
    @property(Node) 球组: Node = null;
    @property(Material) 内描边: Material = null;
    @property(Prefab) 彩带: Prefab = null;

    readonly c存在最大数 = 50
    readonly b倍数 = 1
    readonly z总类型 = [636, 1, 2, 3, 11, 12, 13, 16, 17, 18, 22, 23, 24, 5, 6, 7, 26, 27, 28, 9, 131, 232, 333, 434]

    ty: tongyongTS

    HC_XGQ_chuangguangshu = 0
    HC_doudongshu = 0

    s生成组: number[] = []

    readonly c初始X = -330
    readonly c初始y = 587
    readonly j间隔 = 73
    h盒子坐标: Vec3[] = []
    h盒子节点: Node[] = []

    h盒子总数 = 8
    s剩余总数 = 0
    g关卡总数 = 0
    z阻隔线y = 693
    k可收集 = false

    w网格存在 = true
    w网格次数 = 8

    g关卡设计 = [
        [11, 12, 13, 26, 27, 28, 5, 5, 5, 131, 131, 131],
    ]

    ceshi(e: EventTouch) {
        this.p碰动画()

    }

    protected onLoad(): void {
        this.ty = find('通用管理').getComponent(tongyongTS)
        this.HC_XGQ_chuangguangshu = JSON.parse(localStorage.getItem('HC_XGQ_chuangguangshu'))
        this.HC_doudongshu = JSON.parse(localStorage.getItem('HC_doudongshu'))
    }

    start() {
        this.z阻隔线y = find('Canvas/主程序/网子/标准线').worldPosition.y

        if (this.HC_XGQ_chuangguangshu > 1) {
            this.ty.c创建插屏()
        }

        let wz = this.ty.find查找('Canvas/主程序/道具组/按钮_抖一下/数量')
        wz.getComponent(Label).string = this.HC_doudongshu + ''

        let n = this.ty.find查找('Canvas/弹出组/第几关')
        n.setPosition(0, 0)

        if (this.HC_XGQ_chuangguangshu == 0) {
            this.t填充水果(1)
            n.once(Node.EventType.TOUCH_END, this.d第一关点击, this)
        } else {
            this.t填充水果(2)
            n.once(Node.EventType.TOUCH_END, this.d第二关点击, this)
            let num = this.HC_XGQ_chuangguangshu + 1
            let w = this.ty.find查找('Canvas/弹出组/第几关/文字当前关卡1')
            w.getComponent(Label).string = '关卡：' + num
            w = this.ty.find查找('Canvas/弹出组/第几关/文字当前关卡2')
            w.getComponent(Label).string = '关卡：' + num

        }
        let wn = this.ty.find查找('Canvas/主程序/网子')
        wn.on(Node.EventType.TOUCH_END, this.放开执行wz, this)

        let suo = find('Canvas/主程序/shangkuang/锁链/suo')
        this.ty.c持续缩放(suo)
        suo = find('Canvas/主程序/shangkuang/锁链2/suo')
        this.ty.c持续缩放(suo)

        this.s设置上框位置()
    }

    s设置上框位置() {

        for (let i = 0; i < 10; i++) {
            let v = v3(this.c初始X + this.j间隔 * i, this.c初始y)
            this.h盒子坐标.push(v)
        }

    }


    d第一关点击() {
        let n = this.ty.find查找('Canvas/弹出组/第几关')
        tween(n).to(0.3, { position: v3(1600, 0) }).start()
        n = this.ty.find查找('Canvas/主程序/教学组')
        n.active = true
        n = this.ty.find查找('Canvas/主程序/教学组/手指')
        n.setPosition(182, -400)
        let t = tween(n).by(0.5, { position: v3(10, -10) }).by(0.5, { position: v3(-10, 10) })
        tween(n).repeatForever(t).start()
    }

    d第二关点击() {
        let n = this.ty.find查找('Canvas/弹出组/第几关')
        tween(n).to(0.3, { position: v3(1600, 0) }).start()
    }



    放开执行wz() {
        let ts = this.ty.find查找('Canvas/主程序/提示组/对话框')
        let v = v3(0, 45, 0)
        let wzn = this.ty.find查找('Canvas/主程序/提示组/对话框/Label')
        let lab = '该区域无法点击'
        this.ty.t提示(ts, v, wzn, lab)
    }

    点击执行1(e: EventTouch) {
        this.k可收集 = false
        let n: Node = e.target
        n.getComponent(Sprite).customMaterial = this.内描边
        let cz = n.getComponent(Sprite).customMaterial

        //侦测位置是否为网格上
        let tj1 = true
        if (this.w网格存在) {
            let nhz = n.getComponent(BoxCollider2D)
            let v2zu1: Vec2[] = []
            nhz.worldPoints.forEach((e) => {
                v2zu1.push(e)
            });
            for (let i of v2zu1) {
                let ny = i.y
                if (ny > this.z阻隔线y) {
                    tj1 = false
                    break
                }
            }
        }
        if (tj1) {  //移动与消除
            this.k可收集 = true
            cz.setProperty('_OutlineColor', color().fromHEX('#EEA92E'))    //设置颜色
            cz.setProperty('_OutlineSize', 15)           //设置描边大小
        } else {  //提示抖动
            cz.setProperty('_OutlineColor', color().fromHEX('F51717'))    //设置颜色
            cz.setProperty('_OutlineSize', 15)           //设置描边大小

        }

    }

    放开执行1(e: EventTouch) {
        let n: Node = e.target
        n.getComponent(Sprite).customMaterial = null
        if (this.k可收集) {
            this.ty.bofangshenyin(8)
            if (!this.w网格存在) {
                this.w网格次数--
                if (this.w网格次数 <= 0) {
                    this.网格恢复()
                }
            }

            if (this.ty.find查找('Canvas/主程序/教学组').active) {
                let nsz = this.ty.find查找('Canvas/主程序/教学组/手指')
                Tween.stopAllByTarget(nsz)
                nsz.setPosition(1600, 0)
                //  this.ty.find查找('Canvas/主程序/教学组').active = false
            }

            //判断程序
            let h_length = this.h盒子节点.length
            if (h_length < this.h盒子总数) {    //用来判断是否广告开了格子
                let weizhi = 0
                for (let i = 0; i < this.h盒子总数; i++) {
                    if (this.h盒子节点[i] == null) {
                        weizhi = i
                        break
                    }
                }

                let zj = n.getComponent(RigidBody2D)
                zj.enabled = false
                this.h盒子节点.splice(weizhi, 0, n)
                n.setParent(this.ty.find查找('Canvas/主程序/放置球组'))
                n.setRotation(0, 0, 0, 0)
                this.g更新位置()
            }

            if (this.ty.find查找('Canvas/主程序/球组').children.length < this.c存在最大数 && this.s生成组.length > 0) {
                this.s随机生成(0)
            }
        } else {
            this.ty.z震动执行()
            this.ty.bofangshenyin(4)
            let nwangge = this.ty.find查找('Canvas/主程序/网子')
            Tween.stopAllByTarget(nwangge.getComponent(UIOpacity))
            tween(nwangge.getComponent(UIOpacity)).to(0.3, { opacity: 180 }).to(0.3, { opacity: 120 }).start()
            tween(nwangge.getComponent(Sprite)).delay(0.2).set({ color: color().fromHEX('CA3636') }).delay(0.2).set({ color: color().fromHEX('FFFFFF') }).start()
            this.ty.d抖动(nwangge)

            let ts = this.ty.find查找('Canvas/主程序/提示组/对话框')
            let v = v3(0, 45, 0)
            let wzn = this.ty.find查找('Canvas/主程序/提示组/对话框/Label')
            let lab = '被网子挡住了'
            this.ty.t提示(ts, v, wzn, lab)
        }
    }

    放开执行2(e: EventTouch) {
        let n: Node = e.target
        n.getComponent(Sprite).customMaterial = null
    }

    g更新位置() {
        //按顺序排列
        this.ty.s节点数组按名字排序(1, this.h盒子节点)
        let daihao = 0
        let donghuaZXZ = []
        for (let n of this.h盒子节点) {
            donghuaZXZ.push(n)
            tween(n)
                .to(0.3, { position: this.h盒子坐标[daihao] })
                .call(() => {
                    let dhs = this.doudongZXZ.indexOf(n)
                    donghuaZXZ.splice(dhs, 1)
                    if (donghuaZXZ.length == 0) {   //最后一个执行1次
                        this.p判断删除()
                    }
                })
                .start()
            daihao++
        }
    }

    p判断删除() {
        let k碰 = false
        let k吃 = false
        let mingzi = ''
        if (this.h盒子节点.length != 0) {
            for (let i = 0; i < this.h盒子节点.length; i++) {
                let nam = this.h盒子节点[i].name
                let shuliang = 0
                for (let nn of this.h盒子节点) {
                    if (nn.name == nam) {
                        shuliang++
                        if (shuliang >= 3) {
                            mingzi = nam
                            k碰 = true
                            break
                        }
                    }
                }
            }
        }

        let chisz: number[] = []
        if (!k碰) {
            if (this.h盒子节点.length != 0) {
                let lssc: number[] = []
                this.h盒子节点.forEach((n: Node) => {
                    lssc.push(JSON.parse(n.name))
                })
                if (this.ty.p判断连续的数字位置(lssc).w位置[0]) {
                    chisz = this.ty.p判断连续的数字位置(lssc).w位置[0]
                    if (chisz.length > 0) {
                        k吃 = true
                    }
                }
            }
        }


        if (k碰 || k吃) {
            this.ty.bofangshenyin(15)
            let sz: Node[] = []
            if (k碰) {
                let cs = 0
                for (let n of this.h盒子节点) {
                    if (n.name == mingzi) {
                        cs++
                        sz.push(n)
                    }
                    if (cs == 3) {
                        break
                    }
                }
            }
            if (k吃) {
                sz.push(this.h盒子节点[chisz[0]])
                sz.push(this.h盒子节点[chisz[1]])
                sz.push(this.h盒子节点[chisz[2]])
            }


            let cishu = 0
            for (let n of sz) {
                let daihao = this.h盒子节点.indexOf(n)  //删除节点所在数组位置
                this.h盒子节点.splice(daihao, 1)
                this.s剩余总数--


                //删除动画
                let p = sz[0].worldPosition.clone()
                tween(n).to(0.3, { worldPosition: p })
                    .call(() => {
                        cishu++
                        if (cishu == 1) {
                            let dh = this.ty.find查找('Canvas/主程序/提示组/炸开')
                            dh.setWorldPosition(p)
                            this.ty.b播放粒子(dh)
                            if (k碰) {
                                this.p碰动画()
                            }
                            if (k吃) {
                                this.c吃动画()
                            }
                            this.g更新位置()
                            this.s刷新指示器()

                            if (this.球组.children.length == 0) {
                                this.s胜利执行()
                            }

                        }
                        n.destroy()
                    })
                    .start()
            }
        } else {
            if (this.h盒子节点.length == this.h盒子总数) {
                this.scheduleOnce(this.s失败执行, 0.3)
            }
        }
    }

    q圈动画() {
        let n1 = this.ty.find查找('Canvas/主程序/动画组/圈/dongquan1')
        let n2 = this.ty.find查找('Canvas/主程序/动画组/圈/dongquan2')
        n1.setPosition(0, 0)
        n2.setPosition(0, 0)
        n2.angle = -250
        tween(n2).to(0.3, { angle: 0 })
            .call(() => {
                n1.setPosition(0, 5000)
                n2.setPosition(0, 5000)
            })
            .start()
    }

    p碰动画() {
        this.ty.z震动执行()
        this.ty.bofangshenyin(29)
        let n = find('Canvas/主程序/动画组/碰')
        n.setPosition(0, 260)
        n.setScale(0.5, 0.5)
        Tween.stopAllByTarget(n)
        tween(n).to(0.2, { position: v3(0, 0) }).start()
        tween(n).to(0.2, { scale: v3(1, 1) })
            .call(() => {
                let zi = find('Canvas/主程序/动画组/星星飞舞')
                zi.setPosition(0, 0)
                this.ty.b播放粒子(zi)
                this.q圈动画()
            })
            .delay(1)
            .set({ position: v3(2000, 0) })
            .start()

        this.l连击执行()
    }

    c吃动画() {
        this.ty.z震动执行()
        this.ty.bofangshenyin(31)
        let n = find('Canvas/主程序/动画组/吃')
        n.setPosition(0, 260)
        n.setScale(0.5, 0.5, 1)
        Tween.stopAllByTarget(n)
        tween(n).to(0.2, { position: v3(0, 0) }).start()
        tween(n).to(0.2, { scale: v3(1, 1, 1) })
            .call(() => {
                let zi = find('Canvas/主程序/动画组/星星飞舞')
                zi.setPosition(0, 0)
                this.ty.b播放粒子(zi)
                this.q圈动画()
            })
            .delay(1)
            .set({ position: v3(2000, 0) })
            .start()

        this.l连击执行()
    }

    l连击执行() {

    }

    t填充水果(a) {
        this.s生成组 = []
        if (this.HC_XGQ_chuangguangshu <= 0) {
            this.g关卡设计[this.HC_XGQ_chuangguangshu].forEach((e) => {
                this.s生成组.push(e)
            })
        } else {
            let sz = []
            let c长度 = 15
            let b倍率 = 2
            let gq = this.HC_XGQ_chuangguangshu
            if (gq >= 1 && gq <= 2) {
                c长度 = 6
                b倍率 = 1 + gq
            } else if (gq >= 3 && gq <= 10) {
                c长度 = 10 + gq
                b倍率 = 2
            } else if (gq >= 11 && gq <= 13) {
                c长度 = 20
                b倍率 = gq - 8
            } else if (gq >= 14 && gq <= 17) {
                c长度 = 21 + gq - 14
                b倍率 = 1
            } else if (gq >= 18) {
                c长度 = 24
                b倍率 = 1 + gq - 17
            }




            if (c长度 > this.z总类型.length) {
                c长度 = this.z总类型.length
            }
            for (let i = 0; i < c长度; i++) {
                sz.push(this.z总类型[i])
            }

            for (let i = 0; i < 3 * b倍率; i++) {
                sz.forEach((e) => {
                    this.s生成组.push(e)
                })
            }

        }

        this.ty.s随机打乱(this.s生成组)
        if (this.s生成组.length > 100) {
            this.s剩余总数 = this.s生成组.length - 3
        } else {
            this.s剩余总数 = this.s生成组.length
        }

        this.s随机生成(0)
    }

    lishiSC: number[]
    s随机生成(a) {
        this.lishiSC = []
        if (this.s生成组.length > this.c存在最大数) {
            for (let k = 0; k < this.c存在最大数; k++) {
                this.lishiSC.unshift(this.s生成组[0])
                this.s生成组.splice(0, 1)
                if (this.s生成组.length == 0) {
                    break
                }
            }
        } else {
            this.lishiSC = this.s生成组
            this.s生成组 = []
        }


        if (this.lishiSC.length > 0) {
            let dh = 0
            for (let n of this.lishiSC) {
                dh++
                let f = () => {
                    let xzuozuixiao = -260
                    let xzuozuida = 260
                    let yzuozuixiao = 200
                    let xqiu = 0
                    let yqiu = yzuozuixiao
                    let children = this.球组.children
                    let cishu = 0
                    for (let i = 0; i < children.length; i++) {
                        let child = children[i];
                        let spacingx = child.getComponent(UITransform).width / 2 + 40
                        let spacingy = child.getComponent(UITransform).height / 2 + 60
                        // 如果新生成的节点的中心与已有节点的中心距离小于 spacing，则重新计算位置
                        if (Math.abs(child.position.x - xqiu) < spacingx && Math.abs(child.position.y - yqiu) < spacingy) {
                            cishu++
                            xqiu = this.ty.Rand(xzuozuixiao, xzuozuida)

                            i = -1; // 重新开始循环，因为位置可能需要再次调整
                            if (cishu > 5) {
                                cishu = 0
                                yqiu += 120

                            }
                        }
                    }
                    let nkl = instantiate(this.z子牌);
                    nkl.setParent(this.球组) // 将生成的敌人加入节点树
                    nkl.setPosition(xqiu, yqiu)
                    nkl.getComponent(RigidBody2D).type = ERigidBody2DType.Dynamic
                    nkl.on(Node.EventType.TOUCH_START, this.点击执行1, this)
                    nkl.on(Node.EventType.TOUCH_END, this.放开执行1, this)
                    nkl.on(Node.EventType.TOUCH_CANCEL, this.放开执行2, this)
                    nkl.on(Node.EventType.TOUCH_END, this.放开执行2, this)

                    nkl.name = n + ''
                    this.g更新造型(nkl)
                }
                this.scheduleOnce(f, 0.1 * dh)

            }
        }


        if (a == 0) {
            this.g关卡总数 = this.s剩余总数
            this.s刷新指示器()
        }
    }

    g更新造型(n: Node) {
        n.getChildByName(n.name).active = true
    }

    s刷新指示器() {
        let n = this.ty.find查找('Canvas/主程序/顶部显示/充能/进度2/剩余文字')
        n.getComponent(Label).string = this.s剩余总数 + ''
        let XX = -350 + 700 * ((this.g关卡总数 - this.s剩余总数) / this.g关卡总数)
        let n1 = find('Canvas/主程序/顶部显示/充能/mask/进度1')
        let n2 = find('Canvas/主程序/顶部显示/充能/进度2')
        tween(n1).to(0.6, { position: v3(XX, n1.position.y) }).start()
        tween(n2).to(0.6, { position: v3(XX, n2.position.y) }).start()

        let w = this.ty.find查找('Canvas/弹出组/第几关/显示组/10fangkua/剩余障碍_文字')
        w.getComponent(Label).string = '剩余麻将：' + this.g关卡总数
    }

    网格恢复() {
        this.w网格存在 = true
        let n = this.ty.find查找('Canvas/主程序/网子')
        n.setPosition(0, 30)
    }

    doudongZXZ = []
    d抖动(nd: Node) {  //(nd：节点，0.3：时间，10：幅度)
        let fu = 30
        let shijian = 1
        if (this.doudongZXZ.indexOf(nd) == -1) {
            this.doudongZXZ.push(nd)
            tween(nd)
                .by(shijian / 8, { position: new Vec3(fu, fu, 0) })
                .by(shijian / 8, { position: new Vec3(- fu, - fu, 0) })
                .by(shijian / 8, { position: new Vec3(-fu, fu, 0) })
                .by(shijian / 8, { position: new Vec3(fu, - fu, 0) })
                .by(shijian / 8, { position: new Vec3(-fu, -fu, 0) })
                .by(shijian / 8, { position: new Vec3(fu, fu, 0) })
                .by(shijian / 8, { position: new Vec3(fu, -fu, 0) })
                .by(shijian / 8, { position: new Vec3(-fu, fu, 0) })
                .call(() => {
                    let dhs = this.doudongZXZ.indexOf(nd)
                    this.doudongZXZ.splice(dhs, 1)
                })
                .start()
        }
    }

    y已胜利 = false
    s胜利执行() {
        if (!this.y已胜利) {
            this.ty.c创建banner(2)
            this.y已胜利 = true
            this.ty.bofangshenyin(14)
            let n = this.ty.find查找('Canvas/弹出组/胜利弹出')
            n.setPosition(-1000, 0)

            if (this.HC_XGQ_chuangguangshu > 4) {
                let n1 = find('Canvas/弹出组/胜利弹出/隐藏按钮')
                n1.setPosition(-2000, 0)
                tween(n1).to(0.3, { position: v3(0, 0) }).start()
            }

            tween(n).to(0.3, { position: v3(0, 0) }).call(() => {
                let caid = instantiate(this.彩带)
                caid.setParent(n)
                let tian = this.ty.find查找('Canvas/弹出组/胜利弹出/按钮_领取')
                this.ty.c持续缩放(tian)
            })
                .start()
        }

    }

    s失败执行() {
        this.ty.bofangshenyin(12)
        this.ty.c创建banner(2)
        let n = this.ty.find查找('Canvas/弹出组/失败弹出')
        n.setPosition(-1000, 0)

        if (this.HC_XGQ_chuangguangshu > 4) {
            let n1 = this.ty.find查找('Canvas/弹出组/失败弹出/隐藏按钮')
            n1.setPosition(-1600, 0)
            tween(n1).delay(2).set({ position: v3(0, 0) }).start()
        }

        tween(n).to(0.3, { position: v3(0, 0) }).call(() => {
            let tian = this.ty.find查找('Canvas/弹出组/失败弹出/按钮_复活')
            this.ty.c持续缩放(tian)

            let wz = this.ty.find查找('Canvas/弹出组/失败弹出/进度文字')
            let numjindu = (((this.g关卡总数 - this.s剩余总数) / this.g关卡总数) * 100).toFixed(1)
            let jdn = this.ty.find查找('Canvas/弹出组/失败弹出/10fangkuai/遮罩/进度条')
            let posx = -323 + 323 * ((this.g关卡总数 - this.s剩余总数) / this.g关卡总数)
            tween(jdn).to(0.5, { position: v3(posx, 0) }).call(() => {
                wz.getComponent(Label).string = numjindu + "%"
            }).start()

        })
            .start()
    }

    下一关() {
        this.ty.g关闭banner()
        this.HC_XGQ_chuangguangshu++
        localStorage.setItem('HC_XGQ_chuangguangshu', JSON.stringify(this.HC_XGQ_chuangguangshu));
        Tween.stopAll()
        director.loadScene('xiaogeqiu')

    }


    //UI
    按钮设置() {
        this.ty.c创建banner(2)
        this.ty.bofangshenyin(1)
        let n = this.ty.find查找('Canvas/弹出组/设置弹出')
        n.setPosition(-1000, 0)
        tween(n).to(0.3, { position: v3(0, 0) }).start()
    }

    按钮设置关闭() {
        this.ty.g关闭banner()
        this.ty.bofangshenyin(1)
        let n = this.ty.find查找('Canvas/弹出组/设置弹出')
        n.setPosition(-1000, 0)
    }

    按钮回主页() {
        this.ty.bofangshenyin(1)
        this.ty.c创建插屏()
        Tween.stopAll()
        director.loadScene('kaishichangjing')

    }

    按钮重开() {
        this.ty.bofangshenyin(1)
        Tween.stopAll()
        director.loadScene('xiaogeqiu')
    }

    道具_抖一下() {
        if (this.HC_doudongshu > 0) {
            this.ty.z震动执行()
            this.球组.children.forEach((e) => {
                let wl = e.getComponent(RigidBody2D)
                wl.wakeUp()
            })

            this.ty.bofangshenyin(16)
            let n = this.ty.find查找('Canvas/主程序/地板组')
            this.d抖动(n)
            n = this.ty.find查找('Canvas/主程序/地板组/框')
            this.d抖动(n)

            this.HC_doudongshu--
            localStorage.setItem('HC_doudongshu', JSON.stringify(this.HC_doudongshu));
            let wz = this.ty.find查找('Canvas/主程序/道具组/按钮_抖一下/数量')
            wz.getComponent(Label).string = this.HC_doudongshu + ''
        } else {
            this.ty.bofangshenyin(4)
            let n = this.ty.find查找('Canvas/主程序/道具组/按钮_抖一下/数量')
            this.ty.d抖动(n)
            let ts = this.ty.find查找('Canvas/主程序/提示组/对话框')
            let v = v3(0, 45, 0)
            let wzn = this.ty.find查找('Canvas/主程序/提示组/对话框/Label')
            let lab = '道具数量不足'
            this.ty.t提示(ts, v, wzn, lab)
        }
    }

    道具_取消() {
        this.ty.bofangshenyin(1)
        let n = this.ty.find查找('Canvas/弹出组/广告提示弹出')
        n.setPosition(-1000, 0)
    }


    道具_刷新弹提示() {
        this.ty.bofangshenyin(1)
        let wz = this.ty.find查找('Canvas/弹出组/广告提示弹出/10fangkuai/描述文字')
        wz.getComponent(Label).string = '使用道具刷新\n可重置所有位置'

        let n_an = this.ty.find查找('Canvas/弹出组/广告提示弹出/按钮_观看')
        n_an.off(Button.EventType.CLICK)
        n_an.on(Button.EventType.CLICK, this.道具_刷新, this);

        let n = this.ty.find查找('Canvas/弹出组/广告提示弹出')
        n.setPosition(0, 0)
        if (SJTS.z直接播放) {
            this.道具_刷新()
        }
    }


    道具_打开弹提示() {
        this.ty.bofangshenyin(1)

        let wz = this.ty.find查找('Canvas/弹出组/广告提示弹出/10fangkuai/描述文字')
        wz.getComponent(Label).string = '使用打开道具\n临时打开网子，任意点取'

        let n_an = this.ty.find查找('Canvas/弹出组/广告提示弹出/按钮_观看')
        n_an.off(Button.EventType.CLICK)
        n_an.on(Button.EventType.CLICK, this.道具_去网格, this);

        let n = this.ty.find查找('Canvas/弹出组/广告提示弹出')
        n.setPosition(0, 0)

        if (SJTS.z直接播放) {
            this.道具_去网格()
        }

    }

    道具_解锁格子() {
        this.ty.bofangshenyin(1)
        let wz = this.ty.find查找('Canvas/弹出组/广告提示弹出/10fangkuai/描述文字')
        wz.getComponent(Label).string = '解锁格子\n本局永久开启放置格子'

        let n_an = this.ty.find查找('Canvas/弹出组/广告提示弹出/按钮_观看')
        n_an.off(Button.EventType.CLICK)
        n_an.on(Button.EventType.CLICK, this.道具_加格子, this);

        let n = this.ty.find查找('Canvas/弹出组/广告提示弹出')
        n.setPosition(0, 0)
        if(SJTS.z直接播放){
            this.道具_加格子()
        }
     
    }



    道具_刷新() {
        let f = () => {
            let n = this.ty.find查找('Canvas/弹出组/广告提示弹出')
            n.setPosition(-1000, 0)

            for (let n of this.球组.children) {
                this.s生成组.push(JSON.parse(n.name))
            }
            for (let n of this.球组.children) {
                n.destroy()
            }
            this.ty.s随机打乱(this.s生成组)
            this.s随机生成(1)

        }
        this.ty.c创建激励广告(f)


    }


    道具_去网格() {
        let f = () => {
            let n = this.ty.find查找('Canvas/弹出组/广告提示弹出')
            n.setPosition(-1000, 0)

            this.w网格存在 = false
            n = this.ty.find查找('Canvas/主程序/网子')
            n.setPosition(-1600, 30)
        }
        this.ty.c创建激励广告(f)

    }


    道具_加格子() {
        let f = () => {
            if (this.h盒子总数 == 8) {
                let n = this.ty.find查找('Canvas/弹出组/广告提示弹出')
                n.setPosition(-2000, 0)
                n = this.ty.find查找('Canvas/主程序/shangkuang/锁链')
                n.setPosition(5000, 5000)

                this.h盒子总数 = 9
            } else {
                if (this.h盒子总数 == 9) {
                    let n = this.ty.find查找('Canvas/弹出组/广告提示弹出')
                    n.setPosition(-2000, 0)
                    n = this.ty.find查找('Canvas/主程序/shangkuang/锁链2')
                    n.setPosition(5000, 5000)
                    this.h盒子总数 = 10
                }
            }
        }
        this.ty.c创建激励广告(f)

    }

    复活() {
        this.ty.g关闭banner()
        let f = () => {

            let nt = this.ty.find查找('Canvas/弹出组/失败弹出')
            nt.setPosition(-1600, 0)

            for (let n of this.h盒子节点) {
                this.s生成组.push(JSON.parse(n.name))
            }
            for (let n of this.h盒子节点) {
                n.destroy()
            }
            this.ty.s随机打乱(this.s生成组)
            this.s随机生成(1)

            this.h盒子节点 = []
        }
        this.ty.c创建激励广告(f)

    }

    过关领取() {
        this.ty.g关闭banner()
        let f = () => {
            let nt = this.ty.find查找('Canvas/弹出组/胜利弹出/按钮_领取')
            nt.setPosition(-1600, 0)
            this.HC_doudongshu += 10
            localStorage.setItem('HC_doudongshu', JSON.stringify(this.HC_doudongshu));
            let wz = this.ty.find查找('Canvas/弹出组/胜利弹出/dou/Label')
            wz.getComponent(Label).string = '拥有：' + this.HC_doudongshu
        }
        this.ty.c创建激励广告(f)

    }
}


